<template>
	<view>
		<view class="details_image">
			<u-swiper :list='image_list' height="500" mode="number" interval="3500" border-radius="0"
				indicator-pos="topRight" @click="imgPreview"></u-swiper>
		</view>
		<view class="details_title">
			<view class="details_title_need">需求：<span
					class="details_title_need_name">{{needinfo.demandVarieties}}</span></view>
			<u-icon :name="collect?'heart-fill':'heart'" size="60" label="收藏" label-pos="right" label-size="25"
				style="margin-left: 70rpx;" @click="addcollect()"
				:style="{'color':(collect?'rgba(255, 87, 51, 1)':'rgba(112, 112, 112, 1)')}"></u-icon>
		</view>
		<view class="datails_body">
			<view
				style="height: 100rpx;font-size: 30rpx;color: rgba(255, 87, 51, 1);line-height: 80rpx; border-bottom:1px solid rgba(166, 166, 166, 1);">
				需求详情
			</view>
			<view class="datails_body_text">
				<view class="datails_body_text_title">种类：</view>
				<view class="whitespace">{{needinfo.demandType}}</view>
			</view>
			<view class="datails_body_text">
				<view class="datails_body_text_title">联系人：</view>
				<view class="whitespace">{{needinfo.demandLisisonMan}}</view>
			</view>
			<view class="datails_body_text">
				<view class="datails_body_text_title">需求重量：</view>
				<view class="whitespace">{{needinfo.demandKilogram}}</view>
			</view>
			<view class="datails_body_text">
				<view class="datails_body_text_title">收货地址：</view>
				<view class="whitespace">{{needinfo.detailedAddress}}</view>
			</view>
			<view class="datails_body_text">
				<view class="datails_body_text_title">备注：</view>
				<view class="whitespace">{{needinfo.remarks}}</view>
			</view>
		</view>
		<view class="dateils_foot">
			<view class="buttonview" @click="callphone()">
				<u-icon name="phone" size="48" label="联系买家" label-pos="right" label-size="25" color="#ffffff"
					label-color="#ffffff"></u-icon>
			</view>
		</view>
		<view class="adaptation"></view>

	</view>
</template>

<script>
	// 商品详情页
	export default {
		data() {
			return {
				needuuid: '',
				collect: 0,
				image_list: [{
					image: 'https://pic.dogimg.com/2022/05/08/62776fe3ab35f.png',
					title: " "
				}],
				needinfo: {}
			}
		},
		methods: {
			async addcollect() { //收藏
				console.log(this.collect)
				let url = this.collect ? '/store/cancelStore' : '/store/addStore';
				let data = this.collect ? {
					thingUUId: this.needinfo.demandUuid
				} : {
					thingType: 2,
					thingUUId: this.needinfo.demandUuid
				}
				await this.$myRequest({
					url: url,
					method: 'POST',
					data: data
				}).then(res => {
					if (res.data.code === 200) {
						this.collect = !this.collect;
					} else {
						return 0;
					}
				})
			},
			// placeorder() {
			// 	uni.navigateTo({
			// 		url: '../place_order/place_order'
			// 	})
			// },
			//图片预览 ----- 
			imgPreview(index) {
				uni.previewImage({
					current: 0,
					urls: this.image_list
				})
			},
			callphone() {
				uni.makePhoneCall({
					phoneNumber: this.needinfo.demandContactNumber
				});
			},
			async getproductinfo() {
				const res = await this.$myRequest({
					url: '/demand/getNeedDetails',
					method: 'POST',
					data: {
						'demandUUId': this.needuuid
					}
				}).then(res => {
					if (res.data.code === 200) {
						this.needinfo = res.data.data.data;
						this.collect = res.data.data.colStatus
						this.image_list[0].image = this.needinfo.demandImgUrl;
						// console.log(this.needinfo);

					} else {
						uni.showModal({
							title: '提示',
							content: '数据获取失败,请返回首页',
							showCancel: false,
							success: function() {
								uni.navigateBack()
							}
						})
					}
				})

			}

		},
		onLoad(option) {
			console.log(option.uuid);
			this.needuuid = option.uuid;
			this.getproductinfo();
		}
	}
</script>

<style>
	@import url("demand_details.css");
</style>
